package com.link.ppt.View.Adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.link.ppt.Common.RecyclerView.BaseItem;
import com.link.ppt.Common.RecyclerView.MultiTypeListAdapter;
import com.link.ppt.Model.Bean.PPTEntity;
import com.link.ppt.View.Adapter.Item.PPTStoreItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liucxu on 2018/1/24.
 */

public class PPTStoreAdapter extends MultiTypeListAdapter<PPTEntity> {

    private List<PPTEntity> datas = new ArrayList<>();
    private Context mContext;
    public PPTStoreAdapter(Context c, List<PPTEntity> sources) {
        if (sources != null) {
            datas.clear();
            datas.addAll(sources);
            mContext = c;
        }
    }

    public void setDatas(List<PPTEntity> sources) {
        if (sources != null) {
            datas.clear();
            datas.addAll(sources);
            notifyDataSetChanged();
        }
    }

    public void deleteItem(int position) {
        if ((position >= 0) && (datas.size() > 0)) {
            if (datas.size() - 1 >= position) {
                datas.remove(position);
                notifyItemRemoved(position);
                notifyItemRangeChanged(0,getItemCount());
            }
        }
    }

    @Override
    public PPTEntity getItem(int viewType, int position) {
        return datas.get(position);
    }

    @Override
    public BaseItem<PPTEntity> createItemView(ViewGroup parent, int viewType) {
        return new PPTStoreItem(parent);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
}
